﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Maticsoft.Common;
using DQYT.HTDZ.DBUtility;
using DQYT.HTDZ.BusinessService;
using System.Xml;
using System.Text;
using System.Drawing;
using DQYT.HTDZ.Common;
using DQYT.HTDZ.BLL;
using DQYT.HTDZ.Model;
using Maticsoft.DBUtility;

namespace DQYT.HTDZ.Web.Views.DRAW
{
    public partial class Tzz : System.Web.UI.Page
    {
      
        private BDVALUEModel valuemodel;     
        private BDVALUEBLL valuebll = new BDVALUEBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["id"];
            if (id == "undefined")
            {
                HttpContext.Current.Response.Write("<Script language='JavaScript'>alert('请选择一条数据');window.close();</script>");          
                return;
            }
            string strSql = "select wellid,jcrq from bddatesourse where id= " + id;
            DataTable dt = DbHelperOra.Query(strSql).Tables[0];
            if (dt.Rows.Count < 1)
                return;
            string wellid = dt.Rows[0][0].ToString().Trim();
            string jcrq = dt.Rows[0][1].ToString();
          
            //根据井号和检测日期获得特征值         
            BDValueFunc valueFun = new BDValueFunc();
            valuemodel = valueFun.getValueModel(wellid, jcrq);
            if (valuemodel == null)
                return;
        
            if (!IsPostBack)
            {
                init();
            }
        }
        /// <summary>
        /// 初始化界面
        /// </summary>
        protected void init()
        {
            this.txt_WELLID.Text = valuemodel.WELLID.ToString();
            this.txt_JCRQ.Text = valuemodel.JCRQ.ToString(); 
            this.txt_KSSJ.Text = valuemodel.KSSJ.ToString();
            this.txt_JSSJ.Text = valuemodel.JSSJ.ToString();

            this.txt_CC.Text = getRound(valuemodel.CYJCC);
            this.txt_CCI.Text = getRound(valuemodel.CYJCCI);

            //电机数据
            this.txt_SXDLMAX.Text = getRound(valuemodel.SXDLMAX);
            this.txt_XXDLMAX.Text = getRound(valuemodel.XXDLMAX);
            this.txt_DDZDZPHD.Text = getRound(valuemodel.DDZDZPHD);
            this.txt_SXYGPJZ.Text = getRound(valuemodel.SXYGPJZ);
            this.txt_XXYGPJZ.Text = getRound(valuemodel.XXYGPJZ);
            this.txt_YGPJZPHD.Text = getRound(valuemodel.YGPJZPHD);
            this.txt_SXYGMAX.Text = getRound(valuemodel.SXYGMAX);
            this.txt_XXYGMAX.Text = getRound(valuemodel.XXYGMAX);
            this.txt_YGZDZPHD.Text = getRound(valuemodel.YGZDZPHD);
            this.txt_RWGNH.Text = getRound(valuemodel.RWGNH);
            this.txt_RYGZNH.Text = getRound(valuemodel.RYGZNH);
            this.txt_RYGFNH.Text = getRound(valuemodel.RYGFNH);
            this.txt_YGFZL.Text = getRound(valuemodel.YGFZL);
            this.txt_YGPZL.Text = getRound(valuemodel.YGPZL);
            this.txt_DDJEDGL.Text = getRound(valuemodel.DDJEDGL);

            this.txt_BJ.Text = getRound(valuemodel.BJ);
            this.txt_CYL.Text = getRound(valuemodel.RCYL);
            this.txt_HS.Text = getRound(valuemodel.HS);
            this.txt_DYM.Text = getRound(valuemodel.DYM);
            this.txt_CMD.Text = getRound(valuemodel.CMD);
            this.txt_BX.Text = getRound(valuemodel.BX);
            this.txt_YY.Text = getRound(valuemodel.YY);
            this.txt_TY.Text = getRound(valuemodel.TY);

            
        }
        /// <summary>
        /// 保存修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            
            valuemodel.WELLID=this.txt_WELLID.Text;
            valuemodel.JCRQ = Convert.ToDateTime(this.txt_JCRQ.Text.ToString());
            valuemodel.KSSJ = Convert.ToDateTime(this.txt_KSSJ.Text.ToString());
            valuemodel.JSSJ = Convert.ToDateTime(this.txt_JSSJ.Text.ToString());

            valuemodel.CYJCC = getData(this.txt_CC.Text.ToString());
            valuemodel.CYJCCI = getData(this.txt_CCI.Text.ToString());

            valuemodel.SXDLMAX = getData(this.txt_SXDLMAX.Text.ToString());
            valuemodel.XXDLMAX = getData(this.txt_XXDLMAX.Text.ToString());
            valuemodel.DDZDZPHD = getData(this.txt_DDZDZPHD.Text.ToString());
            valuemodel.SXYGPJZ = getData(this.txt_SXYGPJZ.Text.ToString());
            valuemodel.XXYGPJZ = getData(this.txt_XXYGPJZ.Text.ToString());
            valuemodel.YGPJZPHD = getData(this.txt_YGPJZPHD.Text.ToString());
            valuemodel.SXYGMAX = getData(this.txt_SXYGMAX.Text.ToString());
            valuemodel.XXYGMAX = getData(this.txt_XXYGMAX.Text.ToString());
            valuemodel.YGZDZPHD = getData(this.txt_YGZDZPHD.Text.ToString());

            valuemodel.RWGNH = getData(this.txt_RWGNH.Text.ToString());
            valuemodel.RYGZNH = getData(this.txt_RYGZNH.Text.ToString());
            valuemodel.RYGFNH = getData(this.txt_RYGFNH.Text.ToString());
            valuemodel.YGFZL = getData(this.txt_YGFZL.Text.ToString());
            valuemodel.YGPZL = getData(this.txt_YGPZL.Text.ToString());
            valuemodel.DDJEDGL = getData(this.txt_DDJEDGL.Text.ToString());

            valuemodel.BJ = getData(this.txt_BJ.Text.ToString());
            valuemodel.RCYL = getData(this.txt_CYL.Text.ToString());
            valuemodel.HS = getData(this.txt_HS.Text.ToString());
            valuemodel.DYM = getData(this.txt_DYM.Text.ToString());
            valuemodel.CMD = getData(this.txt_CMD.Text.ToString());
            valuemodel.BX = getData(this.txt_BX.Text.ToString());
            valuemodel.YY = getData(this.txt_YY.Text.ToString());
            valuemodel.TY = getData(this.txt_TY.Text.ToString());
            valuebll.Update(valuemodel);
            JScript.Alert(this.Page, "数据修改成功！");
            //返回父页面一个值Y
            //string strScript = "<script language=javascript>top.window.returnValue=";
            //strScript += "\"Y\"" + ";top.window.close(this);</script>";

            //Response.Write(strScript);
               
        }
         
        #region 计算方法
        /// <summary>
        /// 四舍五入保留小数点后两位
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        protected string getRound(decimal? data)
        {
            double new_data = 0;
            string str = "";
            if (data != 9999999)
            {               
                new_data = Convert.ToDouble(data);
                new_data = Math.Round((new_data + 0.001) * Math.Pow(10, 2)) / Math.Pow(10, 2);
                str = Convert.ToString(new_data);
            }
            return str;

        }

        /// <summary>
        /// 将文本框的值进行非空判断，为空时重新赋值
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        protected decimal getData(string str)
        {
            decimal data = 0;
            if (str =="")
            {
                data = 9999999;
            }
            else
            {
                data = Convert.ToDecimal(str);
            }
            return data;
        }
        #endregion
    }
}